package com.dulian.wallet.controller;

import com.dulian.wallet.common.Result;
import com.dulian.wallet.service.UserWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 用户钱包
 */

@RestController
@RequestMapping("/api/userWallet")
public class UserWalletController {
    @Autowired
    private UserWalletService userWalletService;

    /**
     * 查询用户钱包余额
     * @param userId
     * @return
     */
    @GetMapping("/getUserBalance/{userId}")
    public Result getUserBalance(@PathVariable  String userId) {
        BigDecimal balance = userWalletService.getUserBalance(userId);
        return Result.ok(balance);
    }

    /**
     * 用户消费100元的接口
     * @param userId
     * @param money
     * @return
     */
    @GetMapping("/consume/{userId}/{money}")
    public Result consume(@PathVariable(value = "userId") String userId,
                     @PathVariable(value = "money") String money) {
        Boolean flag = userWalletService.consume(userId, money);
        return Result.ok(flag);
    }

    /**
     * 用户退款20元接口
     * @param userId
     * @param money
     * @return
     */
    @GetMapping("/refund/{userId}/{money}")
    public Result refund(@PathVariable(value = "userId") String userId,
                    @PathVariable(value = "money") String money) {
        Boolean flag = userWalletService.refund(userId, money);
        return Result.ok(flag);
    }
}
